﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SimpleDatabaseAdapter
{
    public class ListDataCollection : IEnumerable, IEnumerator
    {
        private DataTable _dt;
        private ILists _Parent;

        internal ListDataCollection(DataTable dt, ILists parent)
        {
            _dt = dt;
            _Parent = parent;
        }

        public int Count
        {
            get
            {
                return _dt.Rows.Count;
            }
        }
        public ListData this[int index]
        {
            get
            {
                ListData data = new ListData(_dt.Rows[index], _Parent);
                return data;
            }
        }

        // Реализуем интерейс IEnumerable
        public IEnumerator GetEnumerator()
        {
            return this;
        }

        // Реализуем интерфейс IEnumerator
        private int index = -1;
        public bool MoveNext()
        {
            if (index == Count - 1)
            {
                Reset();
                return false;
            }

            index++;
            return true;
        }
        public void Reset()
        {
            index = -1;
        }
        public object Current
        {
            get
            {
                return this[index];
            }
        }
    }
}
